﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace CPPEI.EBS.Data
{
    public static class AuthAppMgr
    {
        private static List<AuthApp> s_appList = new List<AuthApp>();

        /// <summary>
        /// 从配置文件中读取授权的应用程序信息
        /// </summary>
        /// <param name="filePath"></param>
        public static void Load(string filePath)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(filePath);

            XmlNodeList xNodeList = xmlDoc.SelectNodes("./AppList/App");
            for (int index = 0; index < xNodeList.Count; index++)
            {
                XmlNode xApp = xNodeList[index];
                try
                {
                    Guid appId = new Guid(xApp.Attributes["Id"].Value);
                    string appToken = xApp.Attributes["Token"].Value;
                    AuthApp app = new AuthApp(appId, appToken);

                    s_appList.Add(app);
                }
                catch(Exception ex)
                {

                }
            }
        }

        public static List<AuthApp> GetList()
        {
            return s_appList;
        }
    }
}
